package com.huawei.eservice.demo;

import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.net.URL;

import io.appium.java_client.android.AndroidDriver;


public class CalculatorUnit {

    private AndroidDriver driver;

    @BeforeClass
    public void setup() throws Exception {
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(CapabilityType.BROWSER_NAME, "");
        cap.setCapability("platformName", "Android");                               // 指定测试平台
        cap.setCapability("deviceName", "D3H7N18131015935");                       // 指定测试机的ID,通过adb命令`adb
        cap.setCapability("platformVersion", "8.1.0");                                // 设置测试机的版本
        cap.setCapability("appPackage", "com.android.calculator2");                 // 将上面获取到的包名和Activity名设置为值
        cap.setCapability("appActivity", ".Calculator");
        cap.setCapability("appWaitActivity", "com.android.calculator2.Calculator"); // A new session could not be created的解决方法
        cap.setCapability("sessionOverride", true);                    // 每次启动时覆盖session，否则第二次后运行会报错不能新建session
        cap.setCapability("newCommandTimeout", 600000); // A new session could not be created的解决方法
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
    }
    @Test
    public void plus() throws InterruptedException {
        // 获取7
//        // 获取+
//        driver.findElement(By.id("com.android.calculator2:id/plus")).click();
//        // 获取3
//        driver.findElement(By.id("com.android.calculator2:id/digit3")).click();
//        // 获取=
//        driver.findElement(By.id("com.android.calculator2:id/equal")).click();

        Thread.sleep(2000);
        driver.findElementById("com.android.calculator2:id/digit7").click();
//        (new TouchAction(driver)).tap(176, 1093).perform();
//        (new TouchAction(driver)).tap(916, 1315).perform();
//        (new TouchAction(driver)).tap(420, 1084).perform();
//        (new TouchAction(driver)).tap(941, 1639).perform();

    }
    @AfterClass
    public void tearDown() throws Exception {
//        driver.quit();                  //彻底退出程序
    }

}
